package tech.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.mapper.FlowerMapper;
import tech.aistar.pojo.Flower;
import tech.aistar.pojo.dto.FlowerQueryDTO;
import tech.aistar.service.FlowerService;
import tech.aistar.service.UserService;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class FlowerServiceImpl implements FlowerService {
    @Autowired
    private FlowerMapper flowerMapper;

    @Override
    public List<Flower> findByOuther(String name, String use, String material, String category, Integer count) {
        List<Flower> flowers = flowerMapper.findByOther(name,use,material,category,count);
        return flowers;
    }

    @Override
    public List<Flower> findByUse(String use) {
        List<Flower> flowers = flowerMapper.findByOther(null,use,null,null,null);
        return flowers;
    }

    @Override
    public PageInfo<Flower> findByOutherPage(String name, String use, String material, String category, Integer count, Integer pageNum, Integer pageSize) {
        // 添加pageNum和pageSize的非空检查，并设置默认值
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 20;
        }
        PageHelper.startPage(pageNum, pageSize);
        // 直接调用当前类的findByOuther方法，而不是通过未注入的flowerService
        List<Flower> list1 = findByOuther(name, use, material, category, count);
        return new PageInfo<>(list1);
    }
    public Flower findById(int id) {
        Flower flower = flowerMapper.findById(id);
        return flower;
    }
}
